<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
};
$(function(){
	$(".ajax_provider").autocomplete("<?=url('Purchase::Order/Provider')?>").result(function(event, data, formatted){});
	$(".more_click").mouseover(function(){
		$(this).next().show();
	}).mouseout(function(){
		$(this).next().hide();
	});
	$(".more_content").mouseover(function(){
		$(this).show();
	}).mouseout(function(){
		$(this).hide();
	});
	$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
	$(".detail").colorbox({width:"95%", height:"70%", iframe:true});
	$("#print_btn").click(function(){
		var ids = get_check();
		if( ! ids)
		{
			alert('请选择采购单！')
			return false;
		}
		window.open("<?=url('Purchase::Order/Print')?>&ids=" + ids);
	});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$(".list_table input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$(".list_table input[type='checkbox']").attr("checked", false);
		}
	});
	$("#unhold_btn").click(function(){
		var ids = get_check();
		if( ! ids)
		{
			alert('请选择采购单！')
			return false;
		}
		if ( ! confirm('确定取消所选单的滞留状态？'))
		{
			return false;
		}
		window.location.href=("<?=url('Purchase::Order/Unhold')?>&ids=" + ids);
		});
});
</script>
<style type="text/css">
.more_content {
	position: absolute;
	top: 2px;
	left: 25px;
	width: 50px;
	background-color: #eeeeee;
	z-index: 100;
	display: none;
	border: 1px solid;
}
.complaint_click:hover{cursor: pointer;}
</style>
<fieldset><legend>查询条件</legend>
<form action="" method="get">
<? include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>采购日期</th>
	<td>
		<input type="text" name="begin_purchase_time" class="datepicker" value="<?=isset($_GET['begin_purchase_time'])?$_GET['begin_purchase_time']:''?>" /> to
		<input type="text" name="end_purchase_time" class="datepicker" value="<?=isset($_GET['end_purchase_time'])?$_GET['end_purchase_time']:''?>" />
	</td>
</tr>
<tr>
	<th>入库日期</th>
	<td>
		<input type="text" name="begin_storage_audit_time" class="datepicker" value="<?=isset($_GET['begin_storage_audit_time'])?$_GET['begin_storage_audit_time']:''?>" /> to
		<input type="text" name="end_storage_audit_time" class="datepicker" value="<?=isset($_GET['end_storage_audit_time'])?$_GET['end_storage_audit_time']:''?>" />
	</td>
</tr>
<tr>
	<th>财务审核日期</th>
	<td>
		<input type="text" name="begin_finance_audit_time" class="datepicker" value="<?=isset($_GET['begin_finance_audit_time'])?$_GET['begin_finance_audit_time']:''?>" /> to
		<input type="text" name="end_finance_audit_time" class="datepicker" value="<?=isset($_GET['end_finance_audit_time'])?$_GET['end_finance_audit_time']:''?>" />
	</td>
</tr>
<tr>
	<th>采购单号</th>
	<td><input type="text" name="purchase_order_number" value="<?=isset($_GET['purchase_order_number']) ? $_GET['purchase_order_number'] : ''?>" /></td>
</tr>
<tr>
	<th>产品编号</th>
	<td><input type="text" name="product_basic_number" value="<?=isset($_GET['product_basic_number']) ? $_GET['product_basic_number'] : ''?>" /> 输入产品编号后六位例如：000001</td>
</tr>
<tr>
	<th>供应商</th>
	<td>
		<input type="text" class="ajax_provider" name="ajax_provider" value="<?=isset($_GET['ajax_provider']) ? $_GET['ajax_provider'] : ''?>"/>
	</td>
</tr>
<tr>
	<th>结款类型</th>
	<td>
		<select name="purchase_order_payment_type">
			<option value="">请选择..</option>
			<? foreach (Q::ini('custom_flag/purchase_order_payment_type') as $pt):?>
			<option value="<?=$pt['value']?>" <?if (isset($_GET['purchase_order_payment_type']) && $_GET['purchase_order_payment_type'] == $pt['value'])echo "selected='selected'" ?>><?=$pt['name']?></option>
			<? endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>采购人员</th>
	<td>
		<select name="purchase_user_id">
			<option value="">请选择..</option>
			<?foreach ($user as $u):?>
			<option value="<?=$u['id']?>" <?if (isset($_GET['purchase_user_id'])&&$_GET['purchase_user_id']==$u['id'])echo "selected='selected'"?>><?=$u['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>仓库</th>
	<td>
		<select name="warehouse_id">
			<option value="">请选择..</option>
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if (isset($_GET['warehouse_id'])&&$_GET['warehouse_id']==$w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>筛选条件</th>
	<td>
		<label><input type="checkbox" name="is_diff_flag" value="1" <?if (!empty($_GET['is_diff_flag']))echo "checked='checked'"?>/> 预计总价≠实际总价</label>
		<label><input type="checkbox" name="timeout_purchase_order" value="1" <?if (!empty($_GET['timeout_purchase_order']))echo "checked='checked'"?>/> 超时采购单</label>
	</td>
</tr>
<tr>
	<th>状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/purchase_order_status') as $ps):?>
		<label><input type="checkbox" name="purchase_order_status[<?=$ps['value']?>]" value="<?=$ps['value']?>" <?if (isset($_GET['purchase_order_status']) && array_key_exists($ps['value'], $_GET['purchase_order_status'])) echo "checked='checked'"?> /> <?=$ps['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>财务审核</th>
	<td>
		<?foreach (Q::ini('custom_flag/purchase_order_finance_audit') as $fa):?>
		<label><input type="checkbox" name="finance_audit[<?=$fa['value']?>]" value="<?=$fa['value']?>" <?if (isset($_GET['finance_audit']) && array_key_exists($fa['value'], $_GET['finance_audit'])) echo "checked='checked'";?> /> <?=$fa['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>是否滞留</th>
	<td>
		<?foreach (Q::ini('custom_flag/purchase_hold_flag') as $hf):?>
		<label><input type="checkbox" name="purchase_hold_flag[<?=$hf['value']?>]" value="<?=$hf['value']?>" <?if (isset($_GET['purchase_hold_flag']) && array_key_exists($hf['value'], $_GET['purchase_hold_flag'])) echo "checked='checked'";?> /> <?=$hf['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>

<table class="list_table" id="list" width="98%" >
	<tr>
		<th width="30"></th>
		<th width="80">采购单号</th>
		<th width="60">所属仓库</th>
		<th width="80">采购日期</th>
		<th width="80">完成日期</th>
		<th width="120">到仓日期</th>
		<th width="80">预计入库日期</th>
		<th width="80">入库日期</th>
		<th width="90">财务审核日期</th>
		<th width="50">采购人</th>
		<th width="80">预计总价</th>
		<th width="80">实际总价</th>
		<th width="80">状态</th>
		<th width="80">操作</th>
	</tr>
	<?foreach ($purchase_order as $po):?>
		<tr <?if (($po['purchase_hold_flag']) == Q::ini('custom_flag/purchase_hold_flag/holded/value')):?>bgcolor="#ff8800"<?endif;?>>
		<td><input type="checkbox" value="<?=$po['id']?>" /></td>
		<td><a class="detail" href="<?=url('Purchase::Order/Detail', array('id'=>$po['id']))?>"><?=$po['number']?></a></td>
		<td><?=$po['warehouse_name']?></td>
		<td title="采购人员：<?=isset($po['purchase_user_name']) ? $po['purchase_user_name'] : ''?>"><?=isset($po['purchase_time']) ? date('Y-m-d', strtotime($po['purchase_time'])) : ''?></td>
		<td title="完成人员：<?=isset($po['complete_user_name']) ? $po['complete_user_name'] : ''?>"><?=isset($po['complete_time']) ? date('Y-m-d', strtotime($po['complete_time'])) : ''?></td>
		<td title="到仓人员：<?=isset($po['arrive_user_time']) ? $po['arrive_user_name'] : ''?>"><?=isset($po['arrive_time']) ? $po['arrive_time'] : '';?></td>
		<td><?=isset($po['budget_storage_time']) ? date('Y-m-d', strtotime($po['budget_storage_time'])) : ''?></td>
		<td title="入库人员：<?=isset($po['storage_audit_user_name']) ? $po['storage_audit_user_name'] : ''?>"><?=isset($po['storage_audit_time']) ? date('Y-m-d', strtotime($po['storage_audit_time'])) : ''?></td>
		<td title="财务审核人员：<?=isset($po['finance_audit_user_name']) ? $po['finance_audit_user_name'] : ''?>"><?=isset($po['finance_audit_time']) ? date('Y-m-d', strtotime($po['finance_audit_time'])) : ''?></td>
		<td><?=$po['purchase_user_name']?></td>
		<td><?=sprintf('%.2f', $po['budget_amount'])?></td>
		<td><?=sprintf('%.2f', $po['actual_amount'])?></td>
		<td><?=Helper_BSS_Normal::getIniOne('purchase_order_status', 'value', $po['status'], 'name')?></td>
		<td>
			<a class="detail" href="<?=url('Purchase::Order/Detail', array('id'=>$po['id']))?>">查看</a>
			<div style="float: right;position: relative;">
			<a class="more_click">更多&or;</a>
			<ul class="more_content">
				<?if ($po['status'] == Q::ini('custom_flag/purchase_order_status/new/value')):?>
				<li><a href="<?=url('Purchase::Order/BudgetEdit', array('id'=>$po['id']))?>">修改预计</a></li>
				<li><a href="<?=url('Purchase::Order/Del', array('id'=>$po['id'], Q::ini('unique_token_name')=>Helper_BSS_Normal::genToken()))?>" onclick="if(!confirm('确定删除？')) return false;">删除</a></li>
				<?endif;?>
				<?if ($po['status'] == Q::ini('custom_flag/purchase_order_status/purchasing/value')):?><li><a href="<?=url('Purchase::Order/ActualEdit', array('id'=>$po['id']))?>">填写实际</a></li><?endif;?>
				<?if ($po['status'] == Q::ini('custom_flag/purchase_order_status/purchased/value') || $po['status'] == Q::ini('custom_flag/purchase_order_status/partial_storaged/value') || $po['status'] == Q::ini('custom_flag/purchase_order_status/arrived/value')):?><li><a href="<?=url('Purchase::Order/ActualEdit', array('id'=>$po['id']))?>">修改实际</a></li><?endif;?>
				<?if ($po['purchase_hold_flag'] == Q::ini('custom_flag/purchase_hold_flag/holded/value')):?>
				<li><a href="<?=url('Purchase::Order/Unhold', array('ids'=>$po['id']))?>" onclick="if(!confirm('确定取消滞留？')) return false;">取消滞留</a></li>
				<?endif;?>
				<li><a target="_blank" href="<?=url('Purchase::Order/Print', array('ids'=>$po['id']))?>">无图</a></li>
				<li><a target="_blank" href="<?=url('Purchase::Order/Print', array('ids'=>$po['id'], 'pic' => 1))?>">有图</a></li>
				<?if ($po['status'] != Q::ini('custom_flag/purchase_order_status/storaged/value')):?><li><a target="_blank" href="<?=url('Purchase::Order/Create', array('id' => $po['id']))?>" onclick="if(!confirm('确定复制采购单？')) return false;">复制</a></li><?endif;?>
				<li><a target="_blank" href="<?=url('Purchase::Order/PrintProductBarcode', array('ids'=>$po['id']))?>">条形码</a></li>
			</ul>
			</div>
		</td>
	</tr>
	<?endforeach;?>
</table>
<?=$page?>
<table class="list_table">
<tr><td><label><input type="checkbox" id="check_all" /> 全选</label></td>
<td><input type="button" class="button" value="取消滞留" id="unhold_btn" /></td>
<td><input type="button" class="button" value="合并打印" id="print_btn" /></td></tr>
</table>
搜索条件下的采购预计总价：RMB <strong><?=number_format($budget_amount, 2)?></strong><br />
搜索条件下的采购实际总价：RMB <strong><?=number_format($actual_amount, 2)?></strong><br />
搜索条件下的采购实际数量：<strong><?=$actual_quantity?></strong>
<?php $this->_endblock();?>